iT邦幫忙

2024 iThome 鐵人賽

DAY 24
0
Modern Web

asp.net core 分層架構快速上手系列 第 25

Day24 建立分店(Upsert設置)

  • 分享至 

  • xImage
  •  

打開Upsert.cshtml

  • 移除@{ViewData[“Tittle”]=“Create”
  • @model ClothesMall.Models.Store
  • 將 Category. 用空值取代
  • 依Store Model修改input
@model Store;
<h4>Store</h4>
<hr />
<div class="row">
    <div class="col-md-4">
        <form asp-action="Upsert" enctype="multipart/form-data">
            <input asp-for="Id" hidden />
            <div class="row pb-2">
                <h2 class="text-primary"> @(Model.Id != 0 ? "編輯" : "新增")產品</h2>
                <hr />
            </div>
            <div class="form-group">
                <label asp-for="Name" class="control-label"></label>
                <input asp-for="Name" class="form-control" />
                <span asp-validation-for="Name" class="text-danger"></span>
            </div>
            <div class="form-group">
                <label asp-for="Address" class="control-label"></label>
                <input asp-for="Address" class="form-control" />
                <span asp-validation-for="Address" class="text-danger"></span>
            </div>
            <div class="form-group">
                <label asp-for="City" class="control-label"></label>
                <input asp-for="City" class="form-control" />
                <span asp-validation-for="City" class="text-danger"></span>
            </div>
            <div class="form-group">
                <label asp-for="PhoneNumber" class="control-label"></label>
                <input asp-for="PhoneNumber" class="form-control" />
                <span asp-validation-for="PhoneNumber" class="text-danger"></span>
            </div>
            <div class="form-group">
                <label asp-for="Description" class="control-label"></label>
                <input asp-for="Description" class="form-control" />
                <span asp-validation-for="Description" class="text-danger"></span>
            </div>
            <div class="row">
                <div class="col-6 col-md-3">
                    @if (Model.Id != 0)
                    {
                        <button type="submit" class="btn btn-primary form-control">Edit</button>
                    }
                    else
                    {
                        <button type="submit" class="btn btn-primary form-control">Create</button>
                    }
                </div>
                <div class="col-6 col-md-3">
                    <a asp-controller="Store" asp-action="Index" class="btn btn-secondary border form-control">
                        Back to List
                    </a>
                </div>
            </div>
        </form>
    </div>
</div>

@section Scripts {
    @{
        await Html.RenderPartialAsync("_ValidationScriptsPartial");
    }
}

https://ithelp.ithome.com.tw/upload/images/20240926/20147438OvFlqIPHn2.png

  • 修改_Layout
 <a class="dropdown-item text-dark" asp-area="Admin" asp-controller="Store" asp-action="Index">分店</a>

https://ithelp.ithome.com.tw/upload/images/20240926/20147438lTLbCOFXfj.png
https://ithelp.ithome.com.tw/upload/images/20240926/20147438PNJjZi7c4n.png


上一篇
Day23 建立分店(建立View)
下一篇
Day25 分店與員工管理
系列文
asp.net core 分層架構快速上手31
圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

尚未有邦友留言

立即登入留言